// 用mocktio 模拟feign调用


@SpringBootTest
@AutoConfigureMockMvc
class SubSysIndicatorQueryApiTest {

    @Autowired
    private MockMvc mockMvc;

    @Mock
    private InfEventMonitorRemoteInterface infEventMonitorRemoteInterface;

    @Resource
    private ProcessEventMonitorBusiIndexService processEventMonitorBusiIndexService;

    @Test
    void queryIndicator_002() throws Exception {

        // 入参
        String inStr = "{\n" +
                "    \"indicator\": \"101443702\",\n" +
                "    \"regionId\": \"2901\",\n" +
                "    \"roomName\": \"\",\n" +
                "    \"roomId\": \"\",\n" +
                "    \"subMajor\": \"\",\n" +
                "    \"neName\": \"JQ_ _T_H_773984\",\n" +
                "    \"deviceName\": \"\",\n" +
                "    \"deviceId\": \"\",\n" +
                "    \"neType\": \"\",\n" +
                "    \"portName\": \"\",\n" +
                "    \"neId\": \"\",\n" +
                "    \"rmuid\": \"\",\n" +
                "    \"verdor\": \"\",\n" +
                "    \"serviceCode\": \"\",\n" +
                "    \"mainMajor\": \"\",\n" +
                "    \"objectType\": 607,\n" +
                "    \"sheetId\": \"\",\n" +
                "    \"insProcId\": \"\"\n" +
                "}";

        String url = "/api/eventmonitor/indicatorQuery/queryIndicatorInfo";

        String result = "{\"code\":200,\"data\":[{\"perfList\":[{\"upperThresholdValue\":null,\"unit\":\"dbm\",\"statusDesc\":null,\"underThresholdValue\":null,\"indexNameEng\":\"pmpRpl\",\"factoryName\":\"rxPower\",\"thresholdValue\":null,\"value\":\"0.00\",\"indexNameCh\":\"接收光在\",\"status\":0},{\"upperThresholdValue\":null,\"unit\":\"dbm\",\"statusDesc\":null,\"underThresholdValue\":null,\"indexNameEng\":\"pmpTpl\",\"factoryName\":\"txPower\",\"thresholdValue\":null,\"value\":\"0.00\",\"indexNameCh\":\"发送光在\",\"status\":0},{\"upperThresholdValue\":null,\"unit\":\"mA\",\"statusDesc\":null,\"underThresholdValue\":null,\"indexNameEng\":\"pmpOptLbias\",\"factoryName\":\"currTxBias\",\"thresholdValue\":null,\"value\":\"0\",\"indexNameCh\":\"偏在电流\",\"status\":0},{\"upperThresholdValue\":null,\"unit\":\"℃\",\"statusDesc\":null,\"underThresholdValue\":null,\"indexNameEng\":\"pmpOptLtemp\",\"factoryName\":\"temperature\",\"thresholdValue\":null,\"value\":\"0.00\",\"indexNameCh\":\"单板在\",\"status\":0},{\"upperThresholdValue\":null,\"unit\":\"dbm\",\"statusDesc\":null,\"underThresholdValue\":null,\"indexNameEng\":\"pmpOptBack\",\"factoryName\":\"backfaceOpticalPower\",\"thresholdValue\":null,\"value\":\"0\",\"indexNameCh\":\"背光在\",\"status\":0},{\"upperThresholdValue\":null,\"unit\":\"dbm\",\"statusDesc\":null,\"underThresholdValue\":null,\"indexNameEng\":\"pmpOptVoa\",\"factoryName\":\"opticalAttenuation\",\"thresholdValue\":null,\"value\":\"0\",\"indexNameCh\":\"光\",\"status\":0}],\"collectStatusDesc\":\"成功\",\"objectId\":\"6201HWCSAPRTa35885b1d10ef972\",\"collectStatus\":0}],\"message\":\"\"}";
        LuminousPowerDTO powerDTO = new ObjectMapper().readValue(result, LuminousPowerDTO.class);
        RestResultVO<LuminousPowerDTO> restD = RestResultVOFactory.createSuccessResult(powerDTO);

        Field agentClient = ProcessEventMonitorBusiIndexService.class.getDeclaredField("infEventMonitorRemoteInterface");
        agentClient.setAccessible(true);
        agentClient.set(processEventMonitorBusiIndexService, infEventMonitorRemoteInterface);

        Mockito.when(infEventMonitorRemoteInterface.getLuminousPower(Mockito.any(), Mockito.any(String.class), Mockito.any(String.class)))
                .thenReturn(restD);

        ResultActions resultActions = mockMvc.perform(post(url)
                .content(inStr)  // 发送的数据
                .contentType("application/json;charset=UTF-8"));
        // 响应数据设置编码
        resultActions.andReturn().getResponse().setCharacterEncoding("UTF-8");
        resultActions.andDo(print())
                .andExpect(status().isOk());

    }

 
}
